package cn.tedu.sims.controller;

import cn.tedu.sims.pojo.vo.UserLogLoginListItemVO;
import cn.tedu.sims.service.UserLogLoginService;
import cn.tedu.sims.web.JsonResult;
import com.github.xiaoymin.knife4j.annotations.ApiOperationSupport;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 登陆日志
 */
@RestController
@Api(tags = "登陆日志管理")
@RequestMapping("/usersLog")
public class UserLogLoginController {
    @Autowired
    private UserLogLoginService userLogLoginService;

    @ApiOperation("删除登陆日志")
    @ApiOperationSupport(order = 200)
    @PreAuthorize("hasAuthority('/usersLog/delete/id')")
    @GetMapping("/delete/{id}")
    public JsonResult<Void> delete(@PathVariable Long id){
        userLogLoginService.delete(id);
        return JsonResult.ok();
    }

    @ApiOperation("查看全部登陆日志")
    @ApiOperationSupport(order = 401)
    @PreAuthorize("hasAuthority('/usersLog')")
    @GetMapping("")
    public JsonResult<List<UserLogLoginListItemVO>> list(){
        List<UserLogLoginListItemVO> list=userLogLoginService.list();
        return JsonResult.ok(list);
    }

    @ApiOperation("模糊查看登陆日志")
    @ApiOperationSupport(order = 401)
    @PreAuthorize("hasAuthority('/usersLog/selectByUserName/username')")
    @GetMapping("/selectByUserName/{username}")
    public JsonResult<List<UserLogLoginListItemVO>> like(@PathVariable String username){
        List<UserLogLoginListItemVO> list=userLogLoginService.selectByUserName(username);
        return JsonResult.ok(list);
    }
}
